package jsu.lipengcheng.trafficnet.controlle.admin;

import jsu.lipengcheng.trafficnet.common.PageResult;
import jsu.lipengcheng.trafficnet.common.Result;
import jsu.lipengcheng.trafficnet.pojo.Activity;
import jsu.lipengcheng.trafficnet.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/admin/activity")
public class ActivityControlle {
    @Autowired
    private ActivityService activityService;

    @GetMapping("/{id}")
    public Result getActivity(@PathVariable int id) {
        Activity activity= activityService.selectbyid(id);
        return Result.success(activity);
    }

    @GetMapping("/all")
    public Result getAllActivity() {
       List<Activity> activityList= activityService.selectall();
       return Result.success(activityList);
    }

    @GetMapping("/page")
    public Result selectbypage(Integer page, Integer pageSize, LocalDate start, LocalDate end,Integer score,String name) {
        PageResult pageResult = activityService.selectbypage(page,pageSize,start,end,score,name);
        return Result.success(pageResult);
    }

    @PostMapping("/add")
    public Result addActivity(@RequestBody Activity activity) {
        activityService.insert(activity);
        return Result.success();
    }

    @PutMapping()
    public Result updateActivity(@RequestBody Activity activity) {
        activityService.update(activity);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteActivity(@PathVariable Integer id) {
        activityService.delete(id);
        return Result.success();
    }

    @GetMapping("/status")
    public Result getActivityStatus(Integer status) {
       List<Activity> activityList= activityService.selectbystatus(status);
       return Result.success(activityList);
    }

    @GetMapping("/sum")
    public Result getActivitySum() {
      int sum =  activityService.selectsum();
      return Result.success(sum);
    }

}
